﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoreBDS;

namespace BatDongSan.Manager
{
    public partial class ManMem : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    LoadMember();
                }
            }
            catch { }
        }
        protected void grvMember_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                nlit_Member info = (nlit_Member)e.Row.DataItem;

                Label lbEmail = (Label)e.Row.FindControl("lbEmail");
                lbEmail.Text = info.Email;

                Label lbName = (Label)e.Row.FindControl("lbName");
                lbName.Text = info.FullName;

                LinkButton lnkbtEdit = (LinkButton)e.Row.FindControl("lnkbtEdit");
                lnkbtEdit.PostBackUrl = "~/manager/ManMemUpdate.aspx?id=" + info.MemberId;

                LinkButton lnkbtDelete = (LinkButton)e.Row.FindControl("lnkbtDelete");
                lnkbtDelete.OnClientClick = "return confirm('Bạn có chắc không?')";
                lnkbtDelete.Attributes.Add("id", info.MemberId.ToString());
            }
        }

        protected void lnkbtDelete_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton lnkbtDelete = (LinkButton)sender;
                int id = Convert.ToInt32(lnkbtDelete.Attributes["id"]);

                if (id > 0)
                {
                    if (MemberBll.UpdateIsDeleted(id, true, Utility.strConnect))
                    {
                        lbStatus.Text = "Bạn xóa thành công";
                    }
                    else
                    {
                        lbStatus.Text = "Thất bại rồi bạn à";
                    }
                    LoadMember();
                }
            }
            catch { }
        }
        public void LoadMember()
        {
            try
            {
                List<nlit_Member> list = MemberBll.GetList(false,Utility.strConnect);
                list.RemoveRange(0, 2);
                grvMember.DataSource = list;
                grvMember.DataBind();
            }
            catch { }
        
        }
    }
}